package dk.modified.reshary;

import java.util.ArrayList;

import android.os.Parcel;
import android.os.Parcelable;

public class Category implements Parcelable {

	private int categoryId;
	private String categoryName;
	private int parent;
	private ArrayList<CategorySub> children;

	
	public Category(int categoryId, String categoryName, int parent) {
		this.categoryId = categoryId;
		this.categoryName = categoryName;
		this.parent = parent;
		this.children = new ArrayList<CategorySub>();
	}

	private Category(Parcel in) {
		categoryId = in.readInt();
		categoryName = in.readString();
		parent = in.readInt();
		children = in.readArrayList(CategorySub.class.getClassLoader());
	}
	

	public int getChildrenCount(){
		return children.size();
	}
	
	public void setChildren(ArrayList<CategorySub> children) {
		this.children = children;
	}

	public ArrayList<CategorySub> getChildren() {
		return children;
	}

	public int getParentId() {
		return parent;
	}

	public int getCategoryId() {
		return categoryId;
	}

	public String getCategoryName() {
		return categoryName;
	}

	public CategorySub getChildAtPosition(int i){
		return children.get(i);
	}
	public Boolean hasChild(){
		if(children.size() >= 1) return true;
		else return false;
	}

	@Override
	public int describeContents() {
		// TODO Auto-generated method stub
		return 0;
	}

	public static final Parcelable.Creator<Category> CREATOR = new Parcelable.Creator<Category>() {
		public Category createFromParcel(Parcel in) {
			return new Category(in);
		}

		public Category[] newArray(int size) {
			return new Category[size];
		}
	};

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeInt(categoryId);
		dest.writeString(categoryName);
		dest.writeInt(parent);
		dest.writeList(children);

	}
}
